home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / BIOLOGY / GSRC208A.ZIP / EDKINET.C < prev    next >
C/C++ Source or Header  |  1993-08-18  |  6KB  |  206 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*          GWTOP - Topology         */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*         Kinetics dialog box       */
  14. /*                                   */
  15. /*           QuickC/WIN 1.0          */
  16. /*                                   */
  17. /*   (include here compilers that    */
  18. /*   compiled GWSIM successfully)    */
  19. /*                                   */
  20. /*************************************/
  21.  
  22.  
  23. #include <windows.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "defines.h"                    /* symbols also used in .DLG files        */
  27. #include "globals.h"                    /* gepasi's own symbols                    */
  28. #include "gwtop.h"                        /* macros, function prototypes, etc.    */
  29. #include "gep1.h"                        /* gepasi's variables                    */
  30. #include "topgvar.h"                    /* global variables                        */
  31.  
  32.  
  33. void ReactSel( HWND hKL, int item );
  34.  
  35. #pragma alloc_text( CODE3, ReactSel, EdKinet )
  36.  
  37. void ReactSel( HWND hKL, int item )
  38. {
  39.  int noel, i, j;
  40.  unsigned char subs, prods;
  41.  
  42.  /* empty the kinetics list box                                        */
  43.  SendMessage( hKL, LB_RESETCONTENT, 0, 0 );
  44.  
  45.  /* count the substrates and products                                */
  46.  for( i=0, prods=subs=0; i<MAX_MOL; i++ )
  47.  {
  48.   if( (*rstr)[item][i] > 0 ) prods++;
  49.   else if( (*rstr)[item][i] < 0 ) subs++;
  50.  }
  51.  
  52.  SendMessage( hKL, WM_SETREDRAW, FALSE, 0 );
  53.  
  54.  /* first insert the <not defined> type                                */
  55.  SendMessage( hKL, LB_INSERTSTRING, 0, (DWORD) ktype[NOT].descr );
  56.  ktype[NOT].idx = 0;
  57.  
  58.  /* insert all reaction types that have that number of effectors or less    */
  59.  for( i=1, j=1; i<nrateq; i++)
  60.  {
  61.   if( (ktype[i].nsub <= subs) &&
  62.         (ktype[i].npro <= prods) &&
  63.         (ktype[i].revers == revers[item])
  64.       )
  65.   {
  66.    if( ! lstrcmp( (LPSTR) "mass action", (LPSTR) ktype[i].descr ) )
  67.    {
  68.     if( (ktype[i].nsub == subs) && (ktype[i].npro == prods) )
  69.     {
  70. /*     wsprintf( (LPSTR) szString, "%d", i );
  71.      MessageBox( hKL, szString, (LPSTR) "mass action", MB_ICONINFORMATION );*/
  72.      SendMessage( hKL, LB_INSERTSTRING, j, (DWORD) ktype[i].descr );
  73.      ktype[i].idx = j;
  74.      j++;
  75.       }
  76.     else ktype[i].idx = -1;
  77.    }
  78.    else
  79.    {
  80.     SendMessage( hKL, LB_INSERTSTRING, j, (DWORD) ktype[i].descr );
  81.     ktype[i].idx = j;
  82.     j++;
  83.    }
  84.   }
  85.   else ktype[i].idx = -1;
  86.  }
  87.  SendMessage( hKL, WM_SETREDRAW, TRUE, 0 );
  88.  
  89.  /* highlight the selected kinetic type                            */
  90.  if( kinet[item] != -1 )
  91.   SendMessage( hKL, LB_SETCURSEL, (WORD) ktype[kinet[item]].idx, 0 );
  92. }
  93.  
  94. BOOL FAR PASCAL EdKinet( HWND hDlg, WORD message, WORD wParam, LONG lParam )
  95. {
  96.  static    HWND    hReactLst, hKinetLst, hName;
  97.  int i, j, r;
  98.  
  99.  switch( message )
  100.  {
  101.   case WM_INITDIALOG:                                   /*message: initialize dialog box        */
  102.    lbWidth = 0;                                            /* set the width of the list box to 0    */
  103.  
  104.    /* and show the image on the mirror.            */
  105.    _fmemcpy( (void __far *) kinet,
  106.                 (void __far *) kinetu,
  107.              (size_t) MAX_STEP * sizeof( int ) );
  108.    _fmemcpy( (void __far *) lp,
  109.                 (void __far *) loop,
  110.              (size_t) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  111.    _fmemcpy( (void __far *) nmd,
  112.               (void __far *) nmod,
  113.              (size_t) MAX_STEP * sizeof( unsigned char ) );
  114.    kass = kinass;
  115.    lass = loopass;
  116.    nlps = nloops;
  117.  
  118.    /* get handles to controls                    */
  119.    hKinetLst = GetDlgItem( hDlg, IDC_KINETLST );
  120.    hReactLst = GetDlgItem( hDlg, IDC_REACTLST );
  121.    hName     = GetDlgItem( hDlg, IDSTAT_3 );
  122.  
  123.    /* initialize hReactLst: add all reactions */
  124.    for( i=0; i<nsteps; i++ )
  125.     AddReactLst( hReactLst, i, 1, 0, &totmet, metname, stoiu, intmet, revers, rstr );
  126.  
  127.    /* select the first reaction of hReactLst  */
  128.    SendMessage( hReactLst, LB_SETCURSEL, 0, 0 );
  129.    SendMessage( hName, WM_SETTEXT, 0, (DWORD) (LPSTR) stepname[0] );
  130.    ReactSel( hKinetLst, 0 );
  131.    return( TRUE );
  132.  
  133.   case WM_COMMAND:
  134.    switch( wParam )
  135.    {
  136.     case IDC_REACTLST:
  137.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  138.      {
  139.       i = (int) SendMessage( hReactLst, LB_GETCURSEL, 0, 0 );
  140.       SendMessage( hName, WM_SETTEXT, 0, (DWORD) (LPSTR) stepname[i] );
  141.       ReactSel( hKinetLst, i );
  142.       return( TRUE );
  143.      }
  144.      else return FALSE;
  145.  
  146.     case IDC_KINETLST:
  147.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  148.      {
  149.       r = (int) SendMessage( hReactLst, LB_GETCURSEL, 0, 0 );
  150.       i = (int) SendMessage( hKinetLst, LB_GETCURSEL, 0, 0 );
  151.       if( i != LB_ERR )
  152.       {
  153.        for( j=0; j<nrateq; j++ )
  154.        {
  155.         if( ktype[j].idx == i )
  156.         {
  157.          if( kinet[r] == NOT ) kass++;                    /*increase or decrease kass        */
  158.          if( j == NOT ) kass--;
  159.          if( ktype[kinet[r]].nmodf > 0 )
  160.          {
  161.           nlps--;                                        /*previous type had modfs.        */
  162.           if( ktype[kinet[r]].nmodf == nmd[r] ) lass--;    /*and have been assigned        */
  163.          }
  164.          if( ktype[j].nmodf>0 ) nlps++;                    /*this type has modfs.            */
  165.          kinet[r] = j;                                    /* finally assign kinetic type    */
  166.          break;
  167.         }
  168.        }
  169.       }
  170.       return TRUE;
  171.      }
  172.      else return FALSE;
  173.  
  174.     case IDC_HELP:                        /* Help for this Dialog Box             */
  175.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Kinetics editor" );
  176.      return TRUE;
  177.  
  178.     case IDOK:
  179.      /* copy the altered image to the original        */
  180.      _fmemcpy( (void __far *) kinetu,
  181.                   (void __far *) kinet,
  182.                (size_t) MAX_STEP * sizeof( int ) );
  183.      _fmemcpy( (void __far *) loop,
  184.                   (void __far *) lp,
  185.                (size_t) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  186.      _fmemcpy( (void __far *) nmod,
  187.                   (void __far *) nmd,
  188.                (size_t) MAX_STEP * sizeof( unsigned char ) );
  189.      kinass = kass;
  190.      loopass = lass;
  191.      nloops = nlps;
  192.  
  193.      notsaved = 1;
  194.      /* close the dialog box and return                */
  195.      EndDialog( hDlg, IDOK );
  196.      return TRUE;
  197.  
  198.     case IDCANCEL:
  199.      /* close the dialog box and return            */
  200.      EndDialog( hDlg, IDCANCEL );
  201.      return TRUE;
  202.    }
  203.  
  204.   default: return FALSE;
  205.  }
  206. }